package com.hengpeng.common.scheduling.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.Id;

import com.hengpeng.common.persist.entity.AbstractEntity;
import com.hengpeng.common.persist.entity.AuditedEntity;
import com.hengpeng.common.web.annotation.HtmlInput;
import com.hengpeng.common.web.annotation.HtmlInputType;

@Entity
public class SystemJob extends AbstractEntity implements AuditedEntity
{
	/**
	 * <pre>
	 * 系统作业状态
	 * </pre>
	 * @author pengfangliang
	 * @version 1.0, 2010-9-17
	 */
	public enum SystemJobState
	{
		/**
		 * 运行中
		 */
		RUNING("正在运行"),
		/**
		 * 等待运行
		 */
		WAITING("等待运行");

		private String text;

		SystemJobState(String text)
		{
			this.text = text;
		}

		public String getText()
		{
			return text;
		}

		public void setText(String text)
		{
			this.text = text;
		}
	}

	private static final long serialVersionUID = -2397735988036657801L;

	@HtmlInput(label = "是否可调度", type = HtmlInputType.SELECT, labelProperty = "text", index = 3)
	@Column(length = 30)
	@Enumerated(javax.persistence.EnumType.STRING)
	private BoolValue canRun;

	@Id
	@HtmlInput(label = "作业类名", type = HtmlInputType.LABEL, index = 1)
	@Column(length = 200)
	private String className;

	@HtmlInput(label = "描述", type = HtmlInputType.LABEL, index = 2)
	@Column(length = 255)
	private String description;

	private Integer failureCount;

	private Long id = 0L;

	@HtmlInput(label = "最后一次结束时间", type = HtmlInputType.LABEL, index = 7)
	private Date lastCompleteTime;

	@HtmlInput(label = "最后运行主机名", type = HtmlInputType.LABEL, index = 4)
	@Column(length = 1000)
	private String lastRunHostName;

	@HtmlInput(label = "最后一次运行序列号", type = HtmlInputType.LABEL, index = 5)
	private Long lastSequence;

	@HtmlInput(label = "最后一次开始时间", type = HtmlInputType.LABEL, index = 6)
	private Date lastStartTime;

	@HtmlInput(label = "运行次数", type = HtmlInputType.LABEL, index = 8)
	private Integer runCount;

	@HtmlInput(label = "运行状态", type = HtmlInputType.RADIOBOX, labelProperty = "text", index = 11)
	@Column(length = 20)
	@Enumerated(javax.persistence.EnumType.STRING)
	private SystemJobState runState;

	@HtmlInput(label = "运行成功次数", type = HtmlInputType.LABEL, index = 9)
	private Integer successCount;

	@HtmlInput(label = "作业名称", type = HtmlInputType.LABEL, index = 0)
	@Column(length = 50)
	private String taskName;

	@HtmlInput(label = "超时次数", type = HtmlInputType.LABEL, index = 10)
	private Integer timeoutCount;

	public BoolValue getCanRun()
	{
		return canRun;
	}

	public String getClassName()
	{
		return className;
	}

	public String getDescription()
	{
		return description;
	}

	public Integer getFailureCount()
	{
		return failureCount;
	}

	public Long getId()
	{
		return id;
	}

	public Date getLastCompleteTime()
	{
		return lastCompleteTime;
	}

	public String getLastRunHostName()
	{
		return lastRunHostName;
	}

	public Long getLastSequence()
	{
		return lastSequence;
	}

	public Date getLastStartTime()
	{
		return lastStartTime;
	}

	public Integer getRunCount()
	{
		return runCount;
	}

	public SystemJobState getRunState()
	{
		return runState;
	}

	public Integer getSuccessCount()
	{
		return successCount;
	}

	public String getTaskName()
	{
		return taskName;
	}

	public Integer getTimeoutCount()
	{
		return timeoutCount;
	}

	public void setCanRun(BoolValue canRun)
	{
		this.canRun = canRun;
	}

	public void setClassName(String className)
	{
		this.className = className;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}

	public void setFailureCount(Integer failureCount)
	{
		this.failureCount = failureCount;
	}

	public void setId(Long id)
	{
		this.id = id;
	}

	public void setLastCompleteTime(Date lastCompleteTime)
	{
		this.lastCompleteTime = lastCompleteTime;
	}

	public void setLastRunHostName(String lastRunHostName)
	{
		this.lastRunHostName = lastRunHostName;
	}

	public void setLastSequence(Long lastSequence)
	{
		this.lastSequence = lastSequence;
	}

	public void setLastStartTime(Date lastStartTime)
	{
		this.lastStartTime = lastStartTime;
	}

	public void setRunCount(Integer runCount)
	{
		if (runCount.intValue() >= 1000000000)
		{// 重置
			this.runCount = 0;
		}
		else
		{
			this.runCount = runCount;
		}
	}

	public void setRunState(SystemJobState runState)
	{
		this.runState = runState;
	}

	public void setSuccessCount(Integer successCount)
	{
		if (successCount.intValue() >= 1000000000)
		{// 重置
			this.successCount = 0;
		}
		else
		{
			this.successCount = successCount;
		}
	}

	public void setTaskName(String taskName)
	{
		this.taskName = taskName;
	}

	public void setTimeoutCount(Integer timeoutCount)
	{
		if (timeoutCount.intValue() >= 1000000000)
		{// 重置
			this.timeoutCount = 0;
		}
		else
		{
			this.timeoutCount = timeoutCount;
		}

	}
}
